'use strict';

import React from 'react';
import Radium from 'radium';
import LoginPic from './LoginPic';
import LoginForm from './LoginForm';
import { LoginValidate, GoIntoSystemExecutor } from 'lightbi-front-project';
import { Goto, LoginInfo, Base64 } from 'lightbi-front-utils';
import { WaitView } from 'lightbi-front-widget';
import IndexHeader from '../common/IndexHeader';

@Radium
class LoginView extends React.Component {
  constructor(props) {
    super(props);
    this.state = { isLoading : true };
    this.jumpUri = this.props.location.query['jumpUri'];
  }

  componentDidMount() {
    if(LoginValidate.isLogin(this.props.location.query)) {
      if(LoginInfo.getIsAdmin()) {
        if(this.jumpUri == null || this.jumpUri.length == 0)
          Goto('/admin/projects', this.context.router);
        else
          Goto(Base64.decode(this.jumpUri), this.context.router);
      } else
        this.setState({ isLoading : false });
    } else
      this.setState({ isLoading : false });
  }

  render() {
    if(this.state.isLoading)
      return <div className="no-user-select" style={{height: '100%', width: '100%', position: 'relative'}}>
               <WaitView isShow={true} type={WaitView.SPIN} />
             </div>;
    else
      return (
          <div className="no-user-select" style={{height: '100%', width: '100%', position: 'relative'}}>
            <IndexHeader router={this.context.router} selectedItem="登录" location={this.props.location} />
            <div style={{ position : 'relative', width : '100%', textAlign : 'center' }} >
              <LoginForm router={this.context.router} location={this.props.location} />
            </div>
          </div>
      );
  }
};

LoginView.contextTypes = {
    router: React.PropTypes.object.isRequired
};

module.exports=LoginView;
